
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class InterceptorLog extends InterceptorsWrapper {

  @override
  onResponse(Response response) async {
    debugPrint("结果状态：${response.statusCode}");
    if (null != response.data) {
      debugPrint("请求结果：${response.data.toString()}");
    }
     return response;
  }

  @override
  Future onError(DioError err) {
    debugPrint("结果错误状态：${err.error.toString()}");
    if (null != err.response) {
      debugPrint("结果错误状态response：${err.response.statusCode}");
      if (null != err.response.data)
      debugPrint("结果错误状态response：${err.response.data.toString()}");
    }
    if (null != err.request) {
      debugPrint("结果错误状态request：${err.request.baseUrl}");
      if (null != err.request.data)
        debugPrint("结果错误状态request：${err.request.data.toString()}");
    }
    return super.onError(err);
  }

  @override
  onRequest(RequestOptions options) async {
    debugPrint("请求method : ${options.method}");
    debugPrint("请求url : ${options.path}");
    debugPrint("请求头　： ${options.headers.toString()}");
    if (null != options.data) {
      debugPrint("请求参数：${options.data.toString()}");
    }
    if (null != options.queryParameters) {
      debugPrint("请求参数：${options.queryParameters.toString()}");
    }
    return options;
  }
}